package com.yj.ccs.abs.web.management.mapper;

import com.yj.ccs.abs.web.management.entity.ParentCompany;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Copyright 2018 (C) Yunjian-VC
 * Created on : 2018/3/16
 * Author     : Unbelievable9
 **/
@Repository
@Mapper
public interface ParentCompanyMapper {

    @Options(useGeneratedKeys = true, keyProperty = "item.id")
    @Insert("INSERT INTO parent_company (`name`, nature, type, create_time) " +
            "VALUES (#{item.name}, #{item.nature}, #{item.type}, NOW())")
    void create(@Param("item") ParentCompany item);

    @Select("SELECT * FROM parent_company WHERE id = #{id} LIMIT 1")
    ParentCompany getById(@Param("id") Long id);

    @Select("SELECT * FROM parent_company WHERE `name` = #{name} AND type = #{type} LIMIT 1")
    ParentCompany getByNameAndType(@Param("name") String name, @Param("type") Integer type);

    @Select("SELECT * FROM parent_company " +
            "WHERE type = #{type} " +
            "ORDER BY create_time DESC")
    List<ParentCompany> getLatestByType(@Param("type") Integer type);
}
